package yawiki.server.util;

public class Toolbox {

    public static String tab(int t) {
        String ret = "";

        for (int i = 0; i < t; i++) {
            ret += "\t";
        }
        return ret;
    }

    public static String straighten(String page) {
        String pageTitle = page.replaceAll("&", "&amp;");
        pageTitle = pageTitle.replaceAll("'", "&apos;");
        // HACK
        pageTitle = pageTitle.replaceAll("&amp;amp;", "&amp;");
        pageTitle = pageTitle.replaceAll("&amp;amp;amp;", "&amp;");
        pageTitle = pageTitle.replaceAll("&amp;apos;", "&apos;");
        return pageTitle;
    }

    public static String tocTab(int t) {
        String ret = "";

        for (int i = 0; i < t; i++) {
            ret += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        }
        return ret;
    }

    public static boolean isRedirect(String data) {
        if (StringUtility.indexOfIgnoreCase(data, "#redirect") != -1) {
            //System.out.println("REDIRECT:" + wikiText);
            return true;
        }
        return false;
    }

    public static boolean isISBN(String ISBN) {
        int alphaCount = 0;
        for (int i = 0; i < ISBN.length(); i++) {
            if (StringUtility.isCharacter(ISBN.charAt(i))) {
                alphaCount++;
            }
        }
        if (alphaCount > 2) {
            return false;
        }

        if (ISBN.length() < 8) {
            return false;
        }
        if (ISBN.length() > 13) {
            return false;
        }

        return true;
    }
}
